import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Response } from './common/response';
import * as Session from 'express-session';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Logger } from '@nestjs/common';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use(
    Session({
      secret: 'keyboard cat',
      rolling: true,
      name: 'tomyself',
      cookie: { maxAge: 1000 * 60 * 60 * 24 * 7 },
    }),
  );
  app.useGlobalInterceptors(new Response());
  // app.useGlobalFilters(new HttpFilter());

  // 注册接口文档
  const options = new DocumentBuilder()
    .setTitle('我的文档')
    .setDescription('描述，。。。')
    .setVersion('1')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('/api-docs', app, document);
  await app.listen(5000);
}
// 打日志
const env = process.env.NODE_ENV || 'development';
const logger = new Logger('Main');
logger.log(`Running in  ${env} mode`);
logger.log(`database host is ${process.env.DB_HOST}`);

bootstrap();
